package com.kj.report.model;

import java.util.List;

public class ReportNewThreeViem {


    private Integer targetId; //指标Id
    private String targetName; // 指标名称
    private Integer parentId; // 父节点Id
    private List<ReportNewThreeViemChild> childTarget;//子节点指标集合
    private Object score;//分数
    private String hintName;//提示名称
    private String explain;//解释



    public void setHintName(String hintName) {
        this.hintName = hintName;
    }

    public String getExplain() {
        return explain;
    }

    public void setExplain(String explain) {
        this.explain = explain;
    }

    public Integer getTargetId() {
        return targetId;
    }

    public void setTargetId(Integer targetId) {
        this.targetId = targetId;
    }

    public String getTargetName() {
        return targetName;
    }

    public void setTargetName(String targetName) {
        this.targetName = targetName;
    }

    public Integer getParentId() {
        return parentId;
    }

    public void setParentId(Integer parentId) {
        this.parentId = parentId;
    }

    public List<ReportNewThreeViemChild> getChildTarget() {
        return childTarget;
    }

    public void setChildTarget(List<ReportNewThreeViemChild> childTarget) {
        this.childTarget = childTarget;
    }

    public Object getScore() {
        return score;
    }

    public void setScore(Object score) {
        this.score = score;
    }

    public String getHintName() {
        return hintName;
    }

    public void setHintName(Integer index,String hintName) {
        switch (index){
            case 1001 :  //情绪指数 算法
                this.childTarget.stream().forEach(param ->
                    param.setHintName(HintEnum.getEnumByKey(Integer.valueOf(param.getAbLive()),null).desc)

                );
                this.score=Integer.valueOf(childTarget.get(0).getAbLive());

                break;
            case 1002 : //睡眠质量
                // this.childTarget.stream().forEach(param ->{
//                    if (param.getScore()!=null&&param.getScore()>95)
//                        param.setHintName(HintEnum.smzl_1.desc);
//                    else if (param.getScore()!=null&&param.getScore()>90&&param.getScore()<=95)
//                        param.setHintName(HintEnum.smzl_2.desc);
//                    else if(param.getScore()!=null&&param.getScore()<=90)
//                        param.setHintName(HintEnum.smzl_3.desc);
//                });
                this.score=(this.getChildTarget().get(0).getScore()*30+this.getChildTarget().get(1).getScore()*70)/100;
                break;
            case 1003 : //实时状态
                this.hintName = null;
                break;
            case 1004 : //BMI
                break;
            case 1005: //营养状态
                this.score=getRsaScore(3);
                StringBuilder s=new StringBuilder();
                this.getChildTarget().stream().filter(param ->{
                    return param.getScore() != null&&param.getScore()<90;
                }).forEach(param ->{
                        s.append(param.getTargetName()+"、");
                });
                if (s.length()>0)
                    this.setHintName("建议补充"+s.substring(0,s.length()-1)+"。");
                else
                    this.setHintName("正常");
                break;
            case 1006: //免疫能力  //指标偏移量 1：正常 2：偏高 3：偏低
                StringBuilder s1006 = getRsaHint();
                if (s1006.length()>0)
                    this.setHintName(s1006+"");
                this.score=getRsaScore(5);
                break;
            case 1007: //消化能力
                StringBuilder s1007 = getRsaHint();
                if (s1007.length()>0)
                    this.setHintName(s1007+"");
                this.score=getRsaScore(15);
                break;
            case 1008: //吸收能力
                StringBuilder s1008 = getRsaHintalive(null);
                if (s1008.length()>0)
                    this.setHintName(s1008+"");
                this.score=getRsaScore(15);
                break;
            case 1009: //代谢能力
                StringBuilder s1009 = getRsaHintalive(3211);
                if (s1009.length()>0)
                    this.setHintName(s1009+"");
                this.score=getRsaScore(10);
                break;
            case 1010://男性功能
                StringBuilder s1010 = getRsaHintalive(null);
                if (s1010.length()>0)
                    this.setHintName(s1010+"");
                this.score=getRsaScore(10);
                break;
            case 1011://女性功能
                StringBuilder s1011 = getRsaHintalive(null);
                if (s1011.length()>0)
                    this.setHintName(s1011+"");
                this.score=getRsaScore(10);
                break;
            case 1012://皮肤评估
                StringBuilder s1012 = getRsaHintalive(3279);
                if (s1012.length()>0)
                    this.setHintName(s1012+"");
                break;





        }
        //this.hintName = hintName;
    }

    public Integer getRsaScore(Integer factor){
        long count = this.childTarget.stream().filter(param -> {
            return param.getAbLevel() != null && param.getAbLevel() > 1;
        }).count();
        return 100-(new Long(count*factor).intValue());
    }

    public StringBuilder getRsaHint(){
        StringBuilder s=new StringBuilder();
        this.getChildTarget().stream().forEach(param -> {

                if (param.getOffset()!=null&&param.getOffset() != 1) {
                    HintEnum hintEnum = HintEnum.getEnumByKey(param.getTargetId(), param.getOffset() + "");
                    if (hintEnum != null)
                        s.append(hintEnum.hintName);
                }

        });
        if (!(s.length()>0))
             s.append("正常");
        return s;
    }



    public StringBuilder getRsaHintalive(Integer key){
        StringBuilder s= new StringBuilder();
        this.getChildTarget().stream().forEach(param ->{
            if (key != null&&param.getTargetId().equals(key)){
                if (param.getOffset()!=null&&param.getOffset() != 1) {
                    HintEnum hintEnum = HintEnum.getEnumByKey(param.getTargetId(), param.getOffset() + "");
                    if (hintEnum != null)
                        s.append(hintEnum.hintName);
                }
            }else {
                if (param.getAbLevel()!=null&&param.getAbLevel()>1){
                    HintEnum hintEnum = HintEnum.getEnumByKey(param.getTargetId(), null);
                    if (hintEnum !=null)
                        s.append(hintEnum.hintName);
                }
            }
        });
        if (!(s.length()>0))
            s.append("正常");
        return s;
    }

    public enum HintEnum{
        qxzs_1(1,"快乐","情绪良好，心灵满足，请继续保持好心情。"),
        qxzs_2(2,"愉悦","情绪较好，心情愉悦，请继续保持好心情。"),
        qxzs_3(3,"平和","情绪平和，心情稳定，请放松心情保持良好状态。"),
        qxzs_4(4,"压抑","情绪低落，心情压抑，关注美好事物，重获愉悦心情。"),
        qxzs_5(5,"郁闷","情绪较差，偶有悲观厌世，关注美好事物，重获愉悦心情"),

        smzl_1(6,"良好","睡眠质量良好，请保持规律作息和舒缓心情。"),
        smzl_2(7,"正常","睡眠质量正常，建议规律作息，舒缓心情。"),
        smzl_3(8,"有待改善","睡眠质量有待改善，与作息时间不规律有关。"),

        mynl_3139_pg(3139,"2","免疫球蛋白轻微异常，可能与各种慢性感染相关，常见于慢性肝脏疾病。"),//偏高
        mynl_3139_pd(3139,"3","免疫球蛋白轻微异常，可能与营养不良、蛋白质摄入不足或贫血有关。"),//偏低
        mynl_3140_pg(3140,"2","扁桃体免疫力偏弱，可能提示扁桃体发炎，常见于感冒、鼻炎、烟酒过量等。"),//偏高
        mynl_3140_pd(3140,"3","扁桃体免疫力偏弱，提示机体免疫功能减退。"),//偏低
        mynl_3141_pg(3141,"2","呼吸道免疫力偏弱，可能提示支气管炎、哮喘等呼吸道疾病。"),//偏高
        mynl_3141_pd(3141,"3","呼吸道免疫力偏弱，提示呼吸道免疫功能减退。"),//偏低
        mynl_3138_pg(3138,"2","脾脏功能偏弱，可能出现贫血、感染和出血倾向。"),//偏高
        mynl_3138_pd(3138,"3","脾脏功能偏弱，可能影响机体免疫力和血容量。"),//偏低
        mynl_3142_pg(3142,"2","消化道免疫力偏弱，可能出现为胃痛、贫血等。"),//偏高
        mynl_3142_pd(3142,"3","消化道免疫力偏弱，可能出现腹痛、腹泻等不适。"),//偏低

        mynl_3137_s(3137,"2","淋巴结轻微异常，可能出现淋巴结肿大。"),
        mynl_3137_d(3137,"3","淋巴结轻微异常，可能出现淋巴结肿大。"),

        xhnl_3103_pg(3103,"2","胃蠕动能力偏弱，可能导致胃肠道功能紊乱。"),//偏高
        mynl_3103_pd(3103,"3","胃蠕动能力偏弱，可能会出现恶心、呕吐、反酸等，甚至引发急慢性胃炎。"),//偏低
        xhnl_3105_pg(3105,"2","小肠蠕动能力偏弱，可能导致腹痛、胀气等不适。"),//偏高
        mynl_3105_pd(3105,"3","小肠蠕动能力偏弱，可能导致便秘、腹胀、腹痛等。"),//偏低

        xsnl_3106(3106,"","胃吸收能力偏弱，可能影响维生素、矿物质和蛋白质利用。"),
        xsnl_3104(3104,"","小肠吸收能力偏弱，可能出现腹泻、乏力、贫血和体重减少。"),

        dxnl_3098(3098,"","脂代谢偏弱，可能出现脂肪肝和血脂异常。"),
        dxnl_3100(3100,"","蛋白质代谢偏弱，可能造成形体水肿甚至影响大脑、心脏的功能。"),
        dxnl_3211_pg(3211,"2","蛋白质代谢偏弱，可能造成形体水肿甚至影响大脑、心脏的功能。"),
        dxnl_3211_pd(3211,"3","糖代谢偏弱，可能提示胰岛β细胞功能低下。"),

        nxgn_3146(3146,"","勃起功能轻微异常，与疾病、心理、药物及生活方式有关。"),
        nxgn_3145(3145,"","睾丸酮分泌轻微异常，可能影响精子分泌和男性生殖功能。"),
        nxgn_3149(3149,"","前列腺增生可能会引起不同程度排尿障碍。"),
        nxgn_3150(3150,"","前列腺炎可能与细菌感染、久坐、饮食辛辣有关。"),

        nxgn_3153_pg(3153,"2","雌性激素偏高，与环境、情绪、内分泌失调有关。"),
        nxgn_3154(3154,"","黄体酮分泌轻微异常，可能影响排卵、妊娠和泌乳。"),
        nxgn_3160(3160,"","阴道炎指数轻微异常可能导致瘙痒、异味。"),
        nxgn_3162(3162,"","乳腺增生可能与激素分泌、精神因素、生活方式和遗传因素有关。"),

        pfpg_3271(3271,"","胶原蛋白轻微异常，可能出现肌肤干燥、皱纹、色斑、毛孔粗大等问题。"),
        pfpg_3272(3272,"","皮肤油脂轻微异常，可能出现痤疮、脂溢性皮炎等皮肤问题。"),
        pfpg_3274(3274,"","皮肤水分轻微异常，可能出现皮肤松弛、干燥、发痒等问题。"),
        pfpg_3279_pg(3279,"2","皮肤角质偏厚，可能出现粉刺、毛孔粗大等皮肤问题。"),
        pfpg_3279_pd(3279,"3","皮肤角质偏薄，可能出现肌肤敏感、发红、易过敏等问题。"),



        xxxx(500,"正常","");

        private  Integer index;
        private  String desc;
        private  String hintName;

        public String getHintName() {
            return hintName;
        }

        public void setHintName(String hintName) {
            this.hintName = hintName;
        }

        //根据key获取val
        public static HintEnum getEnumByKey(Integer key,String desc){
            if(null == key){
                return null;
            }
            for(HintEnum temp: HintEnum.values()){
                if(temp.getIndex().equals(key)){
                    if (desc !=null&&!desc.equals("")){
                        if (temp.getDesc().equals(desc))
                            return temp;
                        else
                            continue;
                    }

                    return temp;
                }
            }
            return null;
        }

        public Integer getIndex() {
            return index;
        }

        public void setIndex(Integer index) {
            this.index = index;
        }

        public String getDesc() {
            return desc;
        }

        public void setDesc(String desc) {
            this.desc = desc;
        }

        HintEnum(Integer index, String desc,String hintName) {
            this.index = index;
            this.desc = desc;
            this.hintName=hintName;
        }
    }

}
